<template>
    <el-container class="container">
      <el-aside class="sidemenu" width="180px">
        <SideMenu2 class="el-menu-container"></SideMenu2>
      </el-aside>
      <el-main style="padding: 0px">
        <router-view></router-view>
      </el-main>
    </el-container>
</template>

<script>
import StateModel from './StateModel'
import DiagnosisTable from './DiagnosisTable'
import SideMenu2 from './SideMenu2'

export default {
  name: 'DiagnosisIndex',
  components: {SideMenu2, DiagnosisTable, StateModel},
  data () {
    return {
      url1: '/P2/lamda',
      ijk: [{
        shebei: '000'
      }],
      okya: {
        name: 'jjj',
        word: 'sdfag'
      }
    }
  },
  methods: {
    monitor () {
      return setInterval(() => {
        this.paint_model(this.url1)
        this.$refs.diagnosistable.RefreshState()
      }, 5000)
    },
    train () {
      this.$message({
        type: 'success',
        message: '开始训练模型参数'
      })
      this.$http({
        url: this.$http.adornUrl('P2/train'),
        method: 'get',
      }).then(response => {
          if (response.data === 1) {
            this.ijk[0].shebei = '111'
            this.$message({
              type: 'success',
              message: '模型训练完成'
            })
          } else {
            this.ijk[0].shebei = '222'
            this.$message('模型训练失败')
          }
        })
        .catch(failResponse => {})
    },
    reset () {
      this.$confirm('此操作将重置模型参数，是否继续？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http({
          url: this.$http.adornUrl('P2/reset'),
          method: 'get',
        }).then(response => {
            if (response.data === 1) {
              this.$message({
                type: 'success',
                message: '已重置'
              })
              this.ijk[0].shebei = '已清除'
            } else {
              this.ijk[0].shebei = '未清除'
            }
          })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消重置'
        })
      })
    },
    paint_model (url) {
      this.$http({
        url: this.$http.adornUrl(url),
        method: 'get',
      }).then(response => {
        this.$refs.state_model.diag = response.data
        this.$refs.state_model.paint_model_1()
        this.$refs.state_model.paint_model_2()
        this.$refs.state_model.paint_model_3()
        this.$refs.state_model.paint_model_4()
        this.$refs.state_model.paint_model_5()
        this.$refs.state_model.paint_model_6()
        this.ijk[0].shebei = this.$refs.state_model.diag[1][0]
      })
        .catch(function (error) {
          console.log(error)
        })
    }
  },
  created () {
    this.timer()
  }
}
</script>

<style scoped>
.container{
  margin: 0;
}
.el-menu-container{
  height: 92vh;
}
</style>
